package com.icons.draw.view;

import com.google.android.maps.GeoPoint;

import data.Coordinate;

/** Class to hold our location information */
public class MapLocation {

	private GeoPoint	mPoint;
	private String		mName;
	public double latitude;
	public double longitude;
	static double R = 6371; // km
	static double PIx = 3.141592653589793;

	public MapLocation(String name,double latitude, double longitude) {
		this.latitude=latitude;
		this.longitude=longitude;
		this.mName = name;
		mPoint = new GeoPoint((int)(latitude*1e6),(int)(longitude*1e6));
	}

	public GeoPoint getPoint() {
		return mPoint;
	}

	public String getName() {
		return mName;
	}
	
	
	public double distanceKM(MapLocation otherCoor)
	{	
		double dLat = toRad(this.latitude-otherCoor.latitude);
		double dLon = toRad(this.longitude-otherCoor.longitude);
	    double a = (Math.sin(dLat / 2) * Math.sin(dLat / 2)) + Math.cos(toRad(this.latitude)) * Math.cos(toRad(otherCoor.latitude)) * (Math.sin(dLon / 2) * Math.sin(dLon / 2));
	    double angle = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
	    return angle* R;	
	}
	
	private double toRad(double val)
	{
		return PIx*val/180;
	}
}
